package bible.test.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WJCTester {

	/**
	 * @param args
	 */
	public static void main(String[] args)throws Exception {
		System.out.println("===== START =====");
		Map<String, String> map = mergeContent( parseFile() );
		for(String key : map.keySet() ){
			System.out.println( key + ":" + map.get(key) );
		}
		System.out.println("===== END =====");
	}
	
	public static List<Map<String,String>> parseFile()throws Exception{
		List<Map<String,String>> maplist = new ArrayList<Map<String,String>>();
		//File txt = new File("d:/wjc.txt");
		FileReader fr = new FileReader("d:/wjc.txt");
		BufferedReader br = new BufferedReader( fr );
		String line = "";
		while( ( line = br.readLine() ) != null ){
			if( line.trim().length() == 0 ){
				continue;
			}
			Map<String, String > map = new HashMap<String, String>();
			int index = line.indexOf(",");
			map.put("empid", line.substring(0, index));
			map.put("info", line.substring(index + 1 ) );
			maplist.add( map );
		}
		br.close();
		return maplist;
	}
	
	public static Map<String, String> mergeContent( List<Map<String,String>> mapList ){
		Map<String, String> map = new HashMap<String, String>();
		for(Map<String,String> lmap : mapList){
			String key = lmap.get("empid");
			if( map.containsKey( key ) ){
				map.put( key, map.get(key) + "," + lmap.get("info") );
			}else{
				map.put(key, lmap.get("info") );
			}
		}
		return map;
	}

}
